home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / mee / vbdao / visdata / indexadd.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-10-06  |  6.5 KB  |  240 lines

  1. VERSION 2.00
  2. Begin Form fIndexAdd 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Add Index"
  6.    ClientHeight    =   2775
  7.    ClientLeft      =   3855
  8.    ClientTop       =   3795
  9.    ClientWidth     =   4905
  10.    ControlBox      =   0   'False
  11.    ForeColor       =   &H00C0C0C0&
  12.    Height          =   3180
  13.    Left            =   3795
  14.    LinkTopic       =   "Form1"
  15.    MaxButton       =   0   'False
  16.    MinButton       =   0   'False
  17.    ScaleHeight     =   2760
  18.    ScaleMode       =   0  'User
  19.    ScaleWidth      =   4932
  20.    Top             =   3450
  21.    Width           =   5025
  22.    Begin CheckBox cPrimaryFlag 
  23.       BackColor       =   &H00C0C0C0&
  24.       Caption         =   "Primary"
  25.       Height          =   252
  26.       Left            =   3570
  27.       TabIndex        =   9
  28.       Tag             =   "OLR"
  29.       Top             =   105
  30.       Value           =   1  'Checked
  31.       Width           =   1092
  32.    End
  33.    Begin TextBox cIndexName 
  34.       BackColor       =   &H00FFFFFF&
  35.       Height          =   288
  36.       Left            =   960
  37.       TabIndex        =   0
  38.       Tag             =   "OLS"
  39.       Top             =   120
  40.       Width           =   2532
  41.    End
  42.    Begin TextBox cFieldNames 
  43.       BackColor       =   &H00FFFFFF&
  44.       Height          =   528
  45.       Left            =   960
  46.       MultiLine       =   -1  'True
  47.       ScrollBars      =   2  'Vertical
  48.       TabIndex        =   1
  49.       Tag             =   "OLS"
  50.       Top             =   480
  51.       Width           =   2532
  52.    End
  53.    Begin ListBox cFieldList 
  54.       BackColor       =   &H00FFFFFF&
  55.       Height          =   1590
  56.       Left            =   960
  57.       Sorted          =   -1  'True
  58.       TabIndex        =   7
  59.       Tag             =   "OLS"
  60.       Top             =   1080
  61.       Width           =   2535
  62.    End
  63.    Begin CheckBox cUniqueFlag 
  64.       BackColor       =   &H00C0C0C0&
  65.       Caption         =   "Unique"
  66.       Height          =   252
  67.       Left            =   3570
  68.       TabIndex        =   8
  69.       Tag             =   "OLR"
  70.       Top             =   525
  71.       Value           =   1  'Checked
  72.       Width           =   1092
  73.    End
  74.    Begin CommandButton OkayButton 
  75.       BackColor       =   &H00C0C0C0&
  76.       Caption         =   "&OK"
  77.       Default         =   -1  'True
  78.       Enabled         =   0   'False
  79.       Height          =   372
  80.       Left            =   3600
  81.       TabIndex        =   4
  82.       Top             =   1320
  83.       Width           =   1212
  84.    End
  85.    Begin CommandButton CloseButton 
  86.       BackColor       =   &H00C0C0C0&
  87.       Cancel          =   -1  'True
  88.       Caption         =   "&Close"
  89.       Height          =   372
  90.       Left            =   3600
  91.       TabIndex        =   5
  92.       Top             =   1920
  93.       Width           =   1212
  94.    End
  95.    Begin Label FieldListLabel 
  96.       BackColor       =   &H00C0C0C0&
  97.       Caption         =   "Fields:"
  98.       Height          =   252
  99.       Left            =   120
  100.       TabIndex        =   6
  101.       Top             =   1080
  102.       Width           =   732
  103.    End
  104.    Begin Label FieldsLabel 
  105.       BackColor       =   &H00C0C0C0&
  106.       Caption         =   "Indexed Fields:"
  107.       Height          =   492
  108.       Left            =   120
  109.       TabIndex        =   3
  110.       Top             =   480
  111.       Width           =   732
  112.    End
  113.    Begin Label NameLabel 
  114.       BackColor       =   &H00C0C0C0&
  115.       Caption         =   "Name:"
  116.       Height          =   252
  117.       Left            =   120
  118.       TabIndex        =   2
  119.       Top             =   120
  120.       Width           =   732
  121.    End
  122. Option Explicit
  123. Sub cFieldList_Click ()
  124.   Dim s As String
  125.   s = cFieldNames
  126.   If Len(s) = 0 Then
  127.     cFieldNames = s + cFieldList
  128.   Else
  129.     cFieldNames = s & ";" & cFieldList
  130.   End If
  131.   cFieldNames.Refresh
  132. End Sub
  133. Sub cFieldNames_Change ()
  134.   If Len(cIndexName) > 0 And Len(cFieldNames) > 0 Then
  135.     OkayButton.Enabled = True
  136.   Else
  137.     OkayButton.Enabled = False
  138.   End If
  139. End Sub
  140. Sub cFieldNames_LostFocus ()
  141.   If Len(cIndexName) > 0 And Len(cFieldNames) > 0 Then
  142.     OkayButton.Enabled = True
  143.   Else
  144.     OkayButton.Enabled = False
  145.   End If
  146. End Sub
  147. Sub cIndexName_LostFocus ()
  148.   If Len(cIndexName) > 0 And Len(cFieldNames) > 0 Then
  149.     OkayButton.Enabled = True
  150.   Else
  151.     OkayButton.Enabled = False
  152.   End If
  153. End Sub
  154. Sub CloseButton_Click ()
  155.   Unload Me
  156. End Sub
  157. Sub Form_Load ()
  158.   Dim t As TableDef
  159.   Dim i As Integer
  160.   If gfAddTableFlag = True Then
  161.     caption = caption & " to " & fTblStru.cTableName
  162.     fTblStru.cFields.Col = 0
  163.     For i = 1 To fTblStru.cFields.Rows - 1
  164.       fTblStru.cFields.Row = i
  165.       cFieldList.AddItem fTblStru.cFields
  166.     Next
  167.   Else
  168.     caption = caption & " to " & fTables.cTableList
  169.     Set t = gCurrentDB.TableDefs(fTables.cTableList)
  170.     For i = 0 To t.Fields.Count - 1
  171.       cFieldList.AddItem t.Fields(i).Name
  172.     Next
  173.   End If
  174. End Sub
  175. Sub Form_Paint ()
  176.   Outlines Me
  177. End Sub
  178. Sub IndexName_Change ()
  179.   If Len(cIndexName) > 0 And Len(cFieldNames) > 0 Then
  180.     OkayButton.Enabled = True
  181.   Else
  182.     OkayButton.Enabled = False
  183.   End If
  184. End Sub
  185. Sub OkayButton_Click ()
  186.   Dim i As New Index
  187.   Dim t As TableDef
  188.   Dim s As String
  189.   On Error GoTo AddIndexErr
  190.   SetHourglass Me
  191.   i.Name = cIndexName
  192.   i.Fields = cFieldNames
  193.   i.Unique = cUniqueFlag
  194.   If gstDataType <> SQLDB Then i.Primary = cPrimaryFlag
  195.   If gfAddTableFlag = False Then
  196.     Set t = gCurrentDB.TableDefs(fTables.cTableList)
  197.     t.Indexes.Append i
  198.   End If
  199.   fTblStru.cIndexes.Row = 1
  200.   fTblStru.cIndexes.Col = 0
  201.   If Len(fTblStru.cIndexes) > 0 Then
  202.     'add a row if the first one isn't blank
  203.     fTblStru.cIndexes.Rows = fTblStru.cIndexes.Rows + 1
  204.   End If
  205.   fTblStru.cIndexes.Row = fTblStru.cIndexes.Rows - 1
  206.   fTblStru.cIndexes.Col = 0
  207.   fTblStru.cIndexes = cIndexName
  208.   fTblStru.cIndexes.Col = 1
  209.   fTblStru.cIndexes = cFieldNames
  210.   fTblStru.cIndexes.Col = 2
  211.   If i.Unique = False Then
  212.     s = "False"
  213.   Else
  214.     s = "True"
  215.   End If
  216.   fTblStru.cIndexes = s
  217.   fTblStru.cIndexes.Col = 3
  218.   If gstDataType = SQLDB Then
  219.     s = "N/A"
  220.   Else
  221.     If i.Primary = False Then
  222.       s = "False"
  223.     Else
  224.       s = "True"
  225.     End If
  226.   End If
  227.   fTblStru.cIndexes = s
  228.   'reset the field for another
  229.   cIndexName = NULL_STR
  230.   cIndexName.SetFocus
  231.   cFieldNames = NULL_STR
  232.   cUniqueFlag = 1
  233.   GoTo AddIndexEnd
  234. AddIndexErr:
  235.   ShowError
  236.   Resume AddIndexEnd
  237. AddIndexEnd:
  238.   ResetMouse Me
  239. End Sub
  240.